<?php
/**
* phpCan - http://idc.anavallasuiza.com/
*
* phpCan is released under the GNU Affero GPL version 3
*
* More information at license.txt
*/

defined('ANS') or die();

if (!$Vars->exists('login')) {
	return;
}

$auth_data = $Vars->arr('login');

if (!$Config->admin_users[$auth_data['user']] || ($Config->admin_users[$auth_data['user']]['password'] != $auth_data['password'])) {
	$Vars->message(__('Ups, the user or password is not correct!'), 'error');
	return;
}

//Save auth cookie
$Vars->setCookie('admin_session_auth', md5($auth_data['user'].$auth_data['password']), 3600*24*30);

$Vars->message(__('Welcome, %s!', $auth_data['user']), 'success');

if (!$Vars->var['referer'] || strstr($Vars->var['referer'], 'login')) {
	redirect(path(''));
} else {
	redirect($Vars->var['referer']);
}
?>